package com.lwj.liwanjia.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.lwj.liwanjia.R;
import com.lwj.liwanjia.bean.IndentDetailBean;
import com.lwj.liwanjia.view.activity.myindent.tuikuantuihuo.TuiKuanActivity;
import com.lwj.liwanjia.view.activity.supermarket.KefuActivity;
import com.superrecycleview.superlibrary.adapter.BaseViewHolder;
import com.superrecycleview.superlibrary.adapter.SuperBaseAdapter;

import java.util.List;

/**
 * Created by Administrator on 2017/9/14.
 */

public class IndentListAdapter extends SuperBaseAdapter<IndentDetailBean.DataBean.CommodityBean> {
    private Context mContext;
    private String status;
    private String tradeId;

    public IndentListAdapter(Context context, List<IndentDetailBean.DataBean.CommodityBean> data, String status, String tradeId) {
        super(context, data);
        mContext = context;
        this.status = status;
        this.tradeId = tradeId;
    }

    @Override
    protected void convert(BaseViewHolder holder, final IndentDetailBean.DataBean.CommodityBean item, int position) {
        if (status.equals("已完成")||status.contains("未同意")) {
            holder.setVisible(R.id.rl_complete, true);
            TextView shouHou = holder.getView(R.id.tv_shouhou);
            TextView tvGoutong = holder.getView(R.id.tv_goutong);
            tvGoutong.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(mContext, "", Toast.LENGTH_SHORT).show();
//                    Intent intent = new Intent(mContext, KefuActivity.class);
//                    mContext.startActivity(intent);
                }
            });
            shouHou.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, TuiKuanActivity.class);
                    intent.putExtra("tradeId", tradeId);
                    intent.putExtra("goods", item);
                    mContext.startActivity(intent);
                }
            });
        } else {
            holder.setVisible(R.id.rl_complete, false);
        }
        Glide.with(mContext).load(item.getCommodityimage()).into((ImageView) holder.getView(R.id.iv_shangpin));
        holder.setText(R.id.tv_shangpin, item.getCommodityname())
                .setText(R.id.tv_jianjie, item.getCommodityinfo())
                .setText(R.id.tv_price, "￥" + item.getCommodityprice())
                .setText(R.id.tv_number, "*" + item.getCommodityNum());
    }

    @Override
    protected int getItemViewLayoutId(int position, IndentDetailBean.DataBean.CommodityBean item) {
        return R.layout.intent_item1;
    }

}
